<script setup>
import { ref, onMounted } from 'vue'

const schoolfellows = ref([])
const hoveredPerson = ref(null)

// 加载校友信息
const loadSchoolfellowInfo = async () => {
  try {
    const response = await fetch('/schoolfellow/SchoolfellowInfo.json')
    const data = await response.json()
    schoolfellows.value = data.people
  } catch (error) {
    console.error('加载校友信息失败:', error)
  }
}

// 处理鼠标悬停
const handleMouseEnter = (person) => {
  hoveredPerson.value = person
}

const handleMouseLeave = () => {
  hoveredPerson.value = null
}

onMounted(() => {
  loadSchoolfellowInfo()
})
</script>

<template>
  <div class="schoolfellow-container">
    <div class="title-section">
        <h2 class="title">『校友风采』</h2>
    </div>
   
    <div class="content-section">
      <!-- 装饰花朵图片 -->
      <img src="/schoolfellow/images/flower1.png" alt="装饰花朵" class="decoration-flower" />
      <!-- 右边装饰花朵图片 -->
      <img src="/schoolfellow/images/flower1.png" alt="装饰花朵" class="decoration-flower-right" />
      
      <div class="people-grid">
      <div 
        v-for="person in schoolfellows" 
        :key="person.id"
        class="person-card"
        @mouseenter="handleMouseEnter(person)"
        @mouseleave="handleMouseLeave"
        :class="{ 'hovered': hoveredPerson?.id === person.id }"
      >
        <div class="avatar-container">
          <img 
            :src="`/${person.avatar}`" 
            :alt="person.name"
            class="avatar"
          />
        </div>
        <div class="person-info">
          <h3 class="name">{{ person.name }}</h3>
          <p class="lifespan">{{ person.birth }} - {{ person.death }}</p>
        </div>
        
        <!-- 悬停时显示的详细信息 -->
        <div class="detailed-info" v-if="hoveredPerson?.id === person.id">
          <h4>{{ person.name }}</h4>
          <p class="description">{{ person.description }}</p>
          <!-- <p class="dates">{{ person.birth }} - {{ person.death }}</p> -->
        </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.schoolfellow-container {
  width: 100vw;
  min-height: 100vh;
  /* padding: 2rem; */
  margin-left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  background-color: white;
}

.title-section {
  width: 100%;
  background-color: white;
  padding: 2rem 0;
  /* margin-bottom: 2rem; */
  /* box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); */
}

.title {
  text-align: center;
  font-size: 2.5rem;
  margin: 0;
  font-weight: bold;
  color: #C9171D;
}

.content-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #C9171D;
  padding: 30px;
  position: relative;
  overflow: hidden;
}

/**左边花朵 */
.decoration-flower {
  position: absolute;
  left: -400px;
  top: 50px;
  width: 800px;
  height: auto;
  opacity: 0.8;
  z-index: 1;
  pointer-events: none;
}

/**右边花朵 */
.decoration-flower-right {
  position: absolute;
  right: -200px;
  top: 50px;
  width: 1000px;
  height: auto;
  opacity: 0.8;
  z-index: 1;
  pointer-events: none;
}

.people-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 2rem;
  width: 100%;
  max-width: 1200px;
  justify-content: center;
  align-content: center;
  /* background:#C9171D; */

  box-sizing: border-box;
  position: relative;
  z-index: 2;
}

.person-card {
  position: relative;
  background:white;
  /* border-radius: 15px; */
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  transition: all 0.3s ease;
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.person-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.4);
}

.person-card.hovered {
  transform: translateY(-8px);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.4);
}

.avatar-container {
  width: 100%;
  height: 226px;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

.avatar {
  width: 170px;
  height: 226px;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.person-card:hover .avatar {
  transform: scale(1.05);
}

.person-info {
  padding: 1.5rem;
  text-align: center;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.name {
  font-size: 1.5rem;
  margin: 0 0 0.5rem 0;
  font-weight: bold;
}

.lifespan {
  margin: 0;
  font-size: 1rem;
  opacity: 0.7;
}

.detailed-info {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(44, 39, 39, 0.69);
  color: white;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  text-align: center;
  opacity: 0;
  animation: fadeIn 0.3s ease forwards;
  overflow-y: auto;
}

.detailed-info h4 {
  font-size: 1.5rem;
  margin: 0 0 0.5rem 0;
}

.detailed-info .description {
  font-size: 0.9rem;
  line-height: 1.4;
  margin: 0 0 0.5rem 0;
}

.detailed-info .dates {
  font-size: 1rem;
  margin: 0;
  opacity: 0.7;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .people-grid {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: auto;
  }
}

@media (max-width: 768px) {
  .people-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
  }
  
  .title {
    font-size: 2rem;
  }
  
  .schoolfellow-container {
    padding: 1rem;
  }
}

@media (max-width: 480px) {
  .people-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}
</style>